package cn.ekgc.bmdsad.day3;


import java.util.*;

public class MyTree {
    private Map<String,String> map = new HashMap<> (  );
    private Map<String,List<String>> map2 = new HashMap<> (  );



    public void add(String parent, String child) {
        map.put(child,parent);//1:1
        //1:n
        List<String> children = map2.get ( parent );
        if (children == null) {
            children = new ArrayList<> (  );
            map2.put ( parent,children );
        }
        children.add ( child );
    }

    public void addAll(String parent, String ...children) {
        for (String child:
             children) {
            add(parent,child);

        }

    }

    public String getParent(String child) {
        return map.get(child);

    }

    public List<String> getChildren(String parent) {
        return map2.get(parent);
    }

    public List<String> getSibling(String c) {
        String parent = getParent ( c );
        List<String> children = getChildren ( parent );
        List<String> sibling = new ArrayList<> (  );
        for (String s:
             children) {
            sibling.add ( s );
        }
        sibling.remove ( c );
        return sibling;
    }

//    public List<String> getAncestor(String d) {
//        String parent = getParent ( d );
//        List<String> ansestor = new ArrayList<> (  );
//        if (parent == null){
//
//            ansestor = Collections.singletonList ( d );
//        }
//        return ansestor;
//
//    }
//
//    public List<String> getDescendant(String f) {
//        String child = getParent ( f );
//        List<String> descendant = new ArrayList<> (  );
//        if (child == null) {
//            descendant= Collections.singletonList ( f );
//        }
//
//        return descendant;
//    }



}
